﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.ServiceModel.Channels;
using System.IO;
using System.Xml;

namespace WcfService
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "ICrossDomainService" in code, svc and config file together.
    public class CrossDomainService : ICrossDomainService
    {
        public Message ProvidePolicyFile()
        {
            try
            {
                FileStream filestream = File.Open(@"ClientAcessPolicy.xml", FileMode.Open);
                //// Either specify ClientAcessPolicy.xml file path properly
                //// or put that in \Bin folder of the console application
                XmlReader reader = XmlReader.Create(filestream);
                System.ServiceModel.Channels.Message result = Message.CreateMessage(MessageVersion.None, string.Empty, reader);
                return result;
            }
            catch (FaultException fe)
            {
                throw new FaultException(fe.Reason, fe.Code, "Exception in ProvidePolicyFile");
            }
            catch (CommunicationException cex)
            {
                throw new CommunicationException("Exception in ProvidePolicyFile " + cex.Message, cex.InnerException);
            }
            catch (Exception exe)
            {
                throw new Exception("Exception in ProvidePolicyFile " + exe.Message, exe.InnerException);
            }
        }

    }
}
